<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
    <link type="text/css" rel="stylesheet" href="/static/admin/plugin/bootstrap-fileinput/css/fileinput.css"/>
</head>
<style>
    .prize_id{
        display: none;
    }

    .count-txt{
        text-align: center;
        font-size: 15px;
        font-weight: bold;
        margin-top: 1%;
    }
    .prize_name{
        display: none;
    }
</style>
<body>
<div class="page-container">
    <div class=" float-e-margins">
        <div class="ibox-content">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">报备房间</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">报备房间添加</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class=" tab-pane active" id="tab-1">

                        <div class="deal-btn">
                            <button class="btn btn-w-m btn-success lastWeekFlow" id="batch-btn">导出数据</button>
                            <!--<button class="btn btn-w-m btn-warning" id="export-btn">导出数据</button>-->
                        </div>
                        <table id="tb_departments"></table>
                    </div>
                    <div class=" tab-pane" id="tab-2">
                        <div class="ibox-content">
                            <form class="form-horizontal" id="form" data-url="/RoomProfitAdd">

                                <div class="form-group" >
                                    <label class="col-sm-2 control-label">
                                        <span class="c-red">*</span>房主ID：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <input type="number" name="u_id" class="form-control" value="">
                                    </div>
                                </div>

                                <div class="form-group" >
                                    <label class="col-sm-2 control-label">
                                        <span class="c-red">*</span>收益比列：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <input type="number" name="percent" class="form-control" value="" placeholder="0-100">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" >
                                        <span class="c-red">*</span>是否允许提现：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <div class="radio i-checks">
                                            <label><input type="radio"  name="withdraw" value="1" checked> <i></i>是</label>
                                            <label><input type="radio" name="withdraw"  value="2"> <i></i> 否</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" >
                                        <span class="c-red">*</span>是否允许兑换：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <div class="radio i-checks">
                                            <label><input type="radio"  name="exchange" value="1" checked> <i></i>是</label>
                                            <label><input type="radio" name="exchange"  value="2"> <i></i> 否</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" >
                                        <span class="c-red">*</span>是否允许代充：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <div class="radio i-checks">
                                            <label><input type="radio"  name="recharge" value="1" checked> <i></i>是</label>
                                            <label><input type="radio" name="recharge"  value="2"> <i></i> 否</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" >
                                        <span class="c-red">*</span>状态：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <div class="radio i-checks">
                                            <label><input type="radio"  name="status" value="1" checked> <i></i>可用</label>
                                            <label><input type="radio" name="status"  value="2"> <i></i>禁用</label>
                                        </div>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                                        <button class="btn btn-primary" type="button" onclick="commonSubmit(this)">添加
                                        </button>
                                    </div>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script>
    $(document).ready(function () {
        initTable();
    });
    function initTable() {
        $('#tb_departments').bootstrapTable({
            url: '/RoomProfitIndexData',         //请求后台的URL（*）
            dataField: "data",
            method: 'get',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            queryParams: queryParams,//传递参数（*）
            showToggle: true,
            showRefresh: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showPaginationSwitch: true,
            minimumCountColumns: 2,             //最少允许的列数

            columns: [{
                field: 'u_id',
                title: '房主ID'
            }, {
                field: 'r_name',
                title: '房间名'
            }, {
                field: 'phone',
                title: '厅主手机号',
                formatter: function (value, row, index) {
                    return row.phone ? row.phone : '未绑定';
                }
            },{
                field: 'percent',
                title: '收益比列'
            },{
                field: 'money',
                title: '剩余收益'
            },{
                field: 'withdraw',
                title: '开放提现',
                formatter: function (value, row, index) {
                    var arr = [];
                    arr[1] = '已开放'; arr[2] = '已禁止';
                    return arr[row.withdraw] ? arr[row.withdraw] : '未知';
                }
            },{
                field: 'recharge',
                title: '开放代充',
                formatter: function (value, row, index) {
                    var arr = [];
                    arr[1] = '已开放'; arr[2] = '已禁止';
                    return arr[row.recharge] ? arr[row.recharge] : '未知';
                }
            },{
                field: 'exchange',
                title: '开放兑换',
                formatter: function (value, row, index) {
                    var arr = [];
                    arr[1] = '已开放'; arr[2] = '已禁止';
                    return arr[row.exchange] ? arr[row.exchange] : '未知';
                }
            },{
                field: 'status',
                title: '状态',
                formatter: function (value, row, index) {
                    var arr = [];
                    arr[1] = '可用'; arr[2] = '禁用';
                    return arr[row.status] ? arr[row.status] : '未知';
                }
            },{
                field: 'create_time',
                title: '创建时间'
            },{
                field: 'update_time',
                title: '更新时间'
            },{
                field: 'Button',
                title: '操作',
                events: operateEvents,
                formatter: operateFormatter
            }],
            //保存的使用
            onEditableSave: function (field, row, oldValue, $el) {
                //可进行异步操作
                $.ajax({
                    type: "get",
                    url: "/RoomProfitEdit",
                    data: row,
                    dataType: 'JSON',
                    success: function (re) {
                        if (re.code === 100) {
                            layer.msg(re.msg, {icon: 1, time: 2000});
                        } else {
                            layer.alert(re.msg,{icon: 2, time: 2000});
                        }
                    },
                    error: function () {
                        layer.alert('服务器开小差了',{icon: 2, time: 2000});
                    },
                    complete: function () {

                    }

                });
            }
        });
    }

    //得到查询的参数

    function queryParams(params) {
        params.offset = params.offset / params.limit + 1;
        console.log(JSON.stringify(params));
        return params;
    }

    function operateFormatter(value, row, index) {
        var prize_status = row.status === 1 ? '禁用' : '启用';
        return [
            '<button type="button"  class="TableChange btn btn-primary btn-sm" style="margin-right:15px;">' + prize_status + '</button>',
            '<button type="button"  class="rechargeRecord btn btn-primary btn-sm" style="margin-right:15px;">代充记录</button>',
            '<button type="button"  class="powerControl btn btn-primary btn-sm" style="margin-right:15px;">权限控制</button>'
        ].join('');
    }

    window.operateEvents = {
        'click .TableChange': function (e, value, row, index) {
            changeStatus('RoomProfitChangeStatus', row, this);
        },
        'click .rechargeRecord': function (e, value, row, index) {
            rechargeRecord('RoomProfitRechargeRecord', row, this);
        },
        'click .powerControl': function (e, value, row, index) {
            powerControl('RoomProfitPowerControl', row, this);
        }

    };
    //导出
    $('.lastWeekFlow').click(function () {
        location.href = '/RoomProfitLastWeekFlow';
    });

    function changeStatus(url, row, obj) {
        var prize_status = row.status === 1 ? '启用' : '禁用';
        row.status === 1 ? row.status = 2 : row.status = 1;
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: url,
            data: {'id': row.id},
            success: function (re) {
                if (re.code === 100) {
                    layer.msg(re.msg, {icon: 1, time: 2000},function () {
                        window.location.reload();
                    });
                    $(obj).html(prize_status);
                } else {
                    layer.alert(re.msg);
                }
            },
            error: function (data) {
                console.log(data.msg);
            }
        });
    }
    
    
    function rechargeRecord(url, row, obj) {
        layer.open({
            type: 2,
            title: ['代充记录','font-size:18px;font-family:宋体;font-weight:700;'],
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '600px'],
            content:"/RoomProfitRechargeRecord"+'?id='+row.id,
            offset:'auto',
            scrollbar:false
        });
    }

    function powerControl(url, row, obj)
    {
        layer.open({
            type: 2,
            title: ['权限控制','font-size:18px;font-family:宋体;font-weight:700;'],
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '400px'],
            content:"/RoomProfitPowerControl"+'?id='+row.id,
            offset:'auto',
            scrollbar:false,
            end:function () {
                window.location.reload();
            }
        });
    }
    // 搜索按钮触发事件
    $(function () {
        $("#eventQuery").click(function () {
            $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
        });

    });
</script>
</body>
</html>